<template>
  <div class="app-container"
       v-loading.fullscreen.lock="allLoading"
       element-loading-text="拼命处理中,请耐心等待"
       element-loading-spinner="el-icon-loading"
       element-loading-background="rgba(0, 0, 0, 0.8)"
  >
    <el-dialog :close-on-click-modal="false&&changeBitFlagIsNone" :title="mainDialogInfo.title" :visible.sync="showDialog"
               width="270px" append-to-body @close="closeDialog">

      <el-form ref="form" :disabled="changeBitFlagIsNone" :model="form" :rules="rules" label-width="10px">
          <el-form-item label="状态" prop="status" label-width="120">
            <el-select v-model="form.status"  placeholder="请选择">
              <el-option v-for="item in dicts.knowledgeDocumentStatusOptions" :key="item.value" :label="item.label" :value="item.value" ></el-option>
            </el-select>
          </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <template v-if="!changeBitFlagIsNone">
          <el-button type="primary" @click="submitMainDialog">确 定</el-button>
        </template>
        <el-button @click="cancelMainDialog">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import { sksDialogFormMixin } from 'sks-plugin-el-erp/lib/dialog-form'
import request from '@/utils/request'
import { getFileNameWithoutExtension } from '@/utils/str'
import { formatFileSize } from 'sks-plugin-el-erp/lib/core'
import { changeDocumentStatus, delKnowledge } from '@/api/knowledge'

export default {
  name: "KnowledgeDocChangeStatusDialog",
  components: {  },
  mixins: [
    sksDialogFormMixin,
  ],
  data() {
    return {
      defaultForm: {
        id: undefined,
        //状态
        status: undefined,
        //备注
        remark: undefined,
      },
      defaultFormNotNull: {
        successList: [],
        errorList: [],
        //上传文件的列表,因为直接将待上传的file push进来无法刷新行信息
        virtualDocumentList: [],
      },
      extra:{
      },
      rules: {
        status: [
          { required: true, message: '请选择状态', trigger: 'change' },
        ],
      },
    }
  },
  beforeCreate() {
    console.log('dicts',this.dicts)
  },
  methods:{
    validateSuccess() {
      let data = this.sksUtils.mergeFromObject({}, this.form);
      if (!this.sksUtils.isNullOrUndefined(this.mainDialogInfo.submitCallback)) {
        this.mainDialogInfo.submitCallback({submitData: data, ref: this})
        return
      }
      switch(data.virtualChangeBitFlag) {
        case this.sksUtils.CHANGE_BIT_FLAG.modify:
          let data1 = {id: this.form.id,status:this.form.status}
          changeDocumentStatus(data1).then(response=>{
            this.sksUtils.msgSuccess("状态变更成功");
          })
          this.closeDialog()
          if (!this.sksUtils.isNullOrUndefined(this.mainDialogInfo.submitCallbackSuccess)){
            this.mainDialogInfo.submitCallbackSuccess({resData: data})
          }
          break;
        default:
          this.sksUtils.msgError("未知的变更标识");
          break;
      }
    },
    closeDialogBefore(){
      console.log('----------closeDialogBefore')
      if(this.mainDialogInfo?.closeCallback){
        this.mainDialogInfo.closeCallback()
      }
    }
  }
}
</script>

